package com.haha.helloworld.recyclerview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.Toast;

import com.haha.helloworld.R;

public class LinearRecyclerViewActivity extends AppCompatActivity {

    private RecyclerView rv_main;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_linear_recycler_view);
        rv_main=(RecyclerView)findViewById(R.id.rv_main);
        rv_main.setLayoutManager(new LinearLayoutManager(LinearRecyclerViewActivity.this));
//        rv_main.setAdapter(new LinearAdapter(LinearRecyclerViewActivity.this));

        //方式二
        rv_main.setAdapter(new LinearAdapter(LinearRecyclerViewActivity.this, new LinearAdapter.OnItemClickListener() {
            //onClick方法会被Adapter里边调用
            @Override
            public void onClick(int pos) {
                Toast.makeText(LinearRecyclerViewActivity.this,"点击了第"+pos+"个item",Toast.LENGTH_SHORT).show();
            }
        }));
    }
}